<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Problems extends Model
{
    use  SoftDeletes;
    protected $table = 'problems';
    protected $fillable = [
        'problem', 'answer'
    ];


    /**
     * 新增常见问题
     * @param $data
     * @return bool
     */
    static public function add($data)
    {
        $re = self::create($data);
        if ($re) {
            return true;
        }
        return false;
    }

    /**
     * 编辑帮助
     * @param $id
     * @param $data
     * @return bool
     */
    static public function edit($id, $data)
    {
        $re = self::find($id);
        $re->problem = $data['problem'];
        $re->answer = $data['answer'];
        if($re->save())
        {
            return true;
        }
        return false;
    }

    public function   scopeTitle($query,$title)
    {
        if($title){
            $query->where('problem','like','%'.$title.'%');

        }

    }

}
